package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.mq.config.RabbitService;
import com.atguigu.gmall.product.mapper.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.instrument.messaging.SleuthMessagingProperties;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 分类与属性管理service实现类
 */
@Transactional
@Service
public class ManageServiceImpl implements ManageService {
    @Autowired
    private BaseCategory1Mapper baseCategory1Mapper;
    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;
    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;
    @Autowired
    private BaseAttrInfoMapper baseAttrInfoMapper;
    @Autowired
    private BaseAttrValueMapper baseAttrValueMapper;
    @Autowired
    private SpuInfoMapper spuInfoMapper;
    @Autowired
    private BaseTrademarkMapper baseTrademarkMapper;
    @Autowired
    private BaseSaleAttrMapper baseSaleAttrMapper;
    @Autowired
    private SpuImageMapper spuImageMapper;
    @Autowired
    private SpuSaleAttrMapper spuSaleAttrMapper;
    @Autowired
    private SpuSaleAttrValueMapper spuSaleAttrValueMapper;
    @Autowired
    private SkuInfoMapper skuInfoMapper;
    @Autowired
    private SkuImageMapper skuImageMapper;
    @Autowired
    private SkuAttrValueMapper skuAttrValueMapper;
    @Autowired
    private SkuSaleAttrValueMapper skuSaleAttrValueMapper;
    @Autowired
    private BaseCategoryViewMapper baseCategoryViewMapper;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedissonClient redissonClient;
    @Autowired
    private RabbitService rabbitService;
    /**
     * 查询所有一级分类列表
     *
     * @return
     */
    @Override
    public List<BaseCategory1> getCategory1List() {
        return baseCategory1Mapper.selectList(null);
    }

    /**
     * 根据一级分类查询二级分类列表
     *
     * @param category1Id
     * @return
     */
    @Override
    public List<BaseCategory2> getCategory2List(Long category1Id) {
        //参数判断
        if (category1Id == null){
            throw new RuntimeException("二级分类查询失败,一级分类不能为空");
        }
        //条件构造
        LambdaQueryWrapper<BaseCategory2> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BaseCategory2::getCategory1Id,category1Id);
        //返回结果
        return baseCategory2Mapper.selectList(wrapper);
    }

    /**
     * 根据二级分类查询三级分类列表
     *
     * @param category2Id
     * @return
     */
    @Override
    public List<BaseCategory3> getCategory3List(Long category2Id) {
        //参数判断
        if (category2Id == null){
            throw new RuntimeException("三级分类查询失败,二级分类不能为空");
        }
        //条件构造
        LambdaQueryWrapper<BaseCategory3> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BaseCategory3::getCategory2Id,category2Id);
        //返回结果
        return baseCategory3Mapper.selectList(wrapper);
    }

    /**
     * 根据分类查询所有规格信息列表:查询1 2 3级分类对应的规格信息列表,若只查询某一个分类下的规格列表则其他分类的值传0
     *
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @Override
    public List<BaseAttrInfo> getBaseAttrInfoList(Long category1Id, Long category2Id, Long category3Id) {
        return baseAttrInfoMapper.selectBaseAttrInfoList(category1Id, category2Id, category3Id);
    }

    /**
     * 新增规格
     *
     * @param baseAttrInfo
     * @return
     */
    @Override
    public BaseAttrInfo saveAttrInfo(BaseAttrInfo baseAttrInfo) {
        //参数校验
        if (baseAttrInfo == null){
            throw new RuntimeException("参数为空");
        }
        //根据id是否已为空,判断为新增还是修改
        if (baseAttrInfo.getId() == null){
            //新增的场合insert info的信息
            baseAttrInfoMapper.insert(baseAttrInfo);
        }else {
            //修改的场合update info的信息
            baseAttrInfoMapper.updateById(baseAttrInfo);
            //删除旧的value表的数据
            LambdaQueryWrapper<BaseAttrValue> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(BaseAttrValue::getAttrId, baseAttrInfo.getId());
            baseAttrValueMapper.delete(wrapper);
        }
        //获取即将保存的value表的数据
        List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();
        // 方式一:保存value表数据前填充info表的id字段(推荐,效率高)
        attrValueList = attrValueList.stream().map(c ->{
            //补全info表的id字段
            c.setAttrId(baseAttrInfo.getId());
            //保存value表数据
            baseAttrValueMapper.insert(c);
            //返回结果
            return c;
        }).collect(Collectors.toList());
        //重新填充value数据
        baseAttrInfo.setAttrValueList(attrValueList);
        //返回结果
        return baseAttrInfo;
    }

    /**
     * 通过平台属性id查询平台属性值的列表信息
     *
     * @param id
     * @return
     */
    @Override
    public List<BaseAttrValue> getValueById(Long id) {
        //参数判断
        if(id == null){
            throw new RuntimeException("平台属性未选择,无法查询属性值信息!!!!");
        }
        //条件构造
        LambdaQueryWrapper<BaseAttrValue> wrapper = new LambdaQueryWrapper<BaseAttrValue>().eq(BaseAttrValue::getAttrId,id);
        //执行查询,获取结果
        List<BaseAttrValue> attrValueList = baseAttrValueMapper.selectList(wrapper);
        return attrValueList;
    }

    /**
     * 分页查询SpuInfo的信息
     *
     * @param category3Id
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage<SpuInfo> getSpuInfoList(Long category3Id, Integer page, Integer size) {
        //条件构造器
        LambdaQueryWrapper<SpuInfo> wrapper = new LambdaQueryWrapper<>();
        //category3Id
        if (category3Id != null){
            wrapper.eq(SpuInfo::getCategory3Id,category3Id);
        }
        //执行查询
        IPage<SpuInfo> spuInfoIPage = spuInfoMapper.selectPage(new Page<>(page,size),wrapper);
        //返回结果
        return  spuInfoIPage;
    }

    /**
     * 分页查询品牌信息
     *
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage<BaseTrademark> getTrademarkList(Integer page, Integer size) {
        return baseTrademarkMapper.selectPage(new Page<>(page,size),null);
    }

    /**
     * 查询所有销售属性信息
     *
     * @return
     */
    @Override
    public List<BaseSaleAttr> getBaseSaleAttr() {
        return baseSaleAttrMapper.selectList(null);
    }

    /**
     * 查询所有品牌信息
     *
     * @return
     */
    @Override
    public List<BaseTrademark> getTrademark() {
        return baseTrademarkMapper.selectList(null);
    }

    /**
     * 保存spu
     *
     * @param spuInfo
     */
    @Override
    public SpuInfo saveSpuInfo(SpuInfo spuInfo) {
        //保存spu信息
        spuInfoMapper.insert(spuInfo);
        //获取spu的id
        Long spuId = spuInfo.getId();
        //保存spu图片信息
        List<SpuImage> spuImageList = spuInfo.getSpuImageList();
        List<SpuImage> dbImage = spuImageList.stream().map(i -> {
            //补全spuId
            i.setSpuId(spuId);
            //新增图片
            spuImageMapper.insert(i);
            return i;
        }).collect(Collectors.toList());
        spuInfo.setSpuImageList(dbImage);
        //保存spu的销售属性信息
        List<SpuSaleAttr> spuSaleAttrList = spuInfo.getSpuSaleAttrList();
        List<SpuSaleAttr> newSpuSaleAttrList = spuSaleAttrList.stream().map(s->{
            //获取销售属性值
            List<SpuSaleAttrValue> spuSaleAttrValueList = s.getSpuSaleAttrValueList();
            //补全spuid
            s.setSpuId(spuId);
            //新增销售属性
            spuSaleAttrMapper.insert(s);
            //新增销售属性值
            List<SpuSaleAttrValue> newSpuSaleAttrValueList = spuSaleAttrValueList.stream().map(v -> {
                //补全信息spuid
                v.setSpuId(spuId);
                //销售属性名称
                v.setSaleAttrName(s.getSaleAttrName());
                //新增销售属性值
                spuSaleAttrValueMapper.insert(v);
                return v;
            }).collect(Collectors.toList());
            s.setSpuSaleAttrValueList(newSpuSaleAttrValueList);
            return s;
        }).collect(Collectors.toList());
        spuInfo.setSpuSaleAttrList(newSpuSaleAttrList);
        //返回对象
        return spuInfo;
    }

    /**
     * 查询spu的图片列表
     *
     * @param spuId
     * @return
     */
    @Override
    public List<SpuImage> getSpuImageList(Long spuId) {
        //拼接条件
        LambdaQueryWrapper<SpuImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SpuImage::getSpuId,spuId);
        //查询列表
        List<SpuImage> spuImages = spuImageMapper.selectList(wrapper);
        return spuImages;
    }

    /**
     * 查询销售属性列表
     *
     * @param id
     * @return
     */
    @Override
    public List<SpuSaleAttr> getSpuSaleAttrList(Long id) {
        List<SpuSaleAttr> spuSaleAttrs = spuSaleAttrMapper.selectSpuSaleAttrList(id);
        return spuSaleAttrs;
    }

    /**
     * 保存sku信息
     *
     * @param skuInfo
     * @return
     */
    @Override
    public SkuInfo saveSkuInfo(SkuInfo skuInfo) {
        //保存skuinfo数据
        skuInfoMapper.insert(skuInfo);
        //获取skuid
        Long skuId = skuInfo.getId();
        //保存skuImage数据
        List<SkuImage> skuImageList = skuInfo.getSkuImageList();
        List<SkuImage> newSkuImageList = skuImageList.stream().map(image->{
            //补全数据
            image.setSkuId(skuId);
            //新增sku图片
            skuImageMapper.insert(image);
            return image;
        }).collect(Collectors.toList());
        skuInfo.setSkuImageList(newSkuImageList);
        //保存skuAttrValue数据
        List<SkuAttrValue> skuAttrValueList = skuInfo.getSkuAttrValueList();
        List<SkuAttrValue> newSkuAttrValueList = skuAttrValueList.stream().map(attrValue->{
            //补全数据
            attrValue.setSkuId(skuId);
            //新增数据
            skuAttrValueMapper.insert(attrValue);
            return attrValue;
        }).collect(Collectors.toList());
        skuInfo.setSkuAttrValueList(newSkuAttrValueList);
        //保存skuSaleAttrValue数据
        List<SkuSaleAttrValue> skuSaleAttrValueList = skuInfo.getSkuSaleAttrValueList();
        List<SkuSaleAttrValue> newSkuSaleAttrValueList = skuSaleAttrValueList.stream().map(sale -> {
            //补全spu
            sale.setSpuId(skuInfo.getSpuId());
            //补全sku
            sale.setSkuId(skuId);
            //新增
            skuSaleAttrValueMapper.insert(sale);
            return sale;
        }).collect(Collectors.toList());
        skuInfo.setSkuSaleAttrValueList(newSkuSaleAttrValueList);
        //返回结果
        return skuInfo;
    }

    /**
     * 分页查询skuinfo的信息
     *
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage<SkuInfo> getSkuInfoList(Integer page, Integer size) {
        return skuInfoMapper.selectPage(new Page<>(page,size),null);
    }


    /**
     * sku上/下架
     *
     * @param skuId
     * @param status :1-上架 0-下架
     */
    @Override
    public SkuInfo UpOrDown(Long skuId, Integer status) {
        if(skuId == null){
            throw new RuntimeException("sku未指定,无法修改sku的上下架状态");
        }
        //查询skuinfo的信息
        SkuInfo skuInfo = skuInfoMapper.selectById(skuId);
        //若为空失败
        if (skuInfo ==null || skuInfo.getId() == null){
            throw new RuntimeException("商品不存在，无法进行上架操作");
        }
        //设置skuinfo的状态
        skuInfo.setIsSale(status);
        //修改skuinfo上下架状态
        skuInfoMapper.updateById(skuInfo);
        //发送一个上架或者下架的消息
        if (status == 0){
            rabbitService.sendMessage("sku_exchange","sku.down",skuInfo.getId()+"");
        }else {
            rabbitService.sendMessage("sku_exchange","sku.upper",skuInfo.getId()+"");
        }

        return skuInfo;
    }

    /**
     * 查询sku的详细信息
     *
     * @param skuId
     * @return
     */
    @Override
    public SkuInfo getSkuInfo(Long skuId) {
        //根据id查询sku信息
        SkuInfo skuInfo = skuInfoMapper.selectById(skuId);
        //查询sku的图片信息
        List<SkuImage> skuImages = skuImageMapper.selectList(new LambdaQueryWrapper<SkuImage>().eq(SkuImage::getSkuId, skuId));
        //保存图片信息
        skuInfo.setSkuImageList(skuImages);
        //返回结果
        return skuInfo;
    }

    /**
     * 查询sku的详细信息：优先从redis中获取，如果redis中没有查询数据库并将数据缓存到redis中
     *
     * @param skuId
     * @return
     */
    @Override
    public SkuInfo getSkuByRedis(Long skuId) {
        //sku:123:info
        String key = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKUKEY_SUFFIX;
        //从缓存中获取sku的信息
        String s = stringRedisTemplate.boundValueOps(key).get();
        //缓存中没有数据
        if (StringUtils.isEmpty(s)){
            //定义锁 sku:123:lock
            String lockKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKULOCK_SUFFIX;
            //随机串
            String uuid = UUID.randomUUID().toString();
            //加锁
            Boolean res = stringRedisTemplate.opsForValue().setIfAbsent(lockKey,uuid,
                    RedisConst.SKULOCK_EXPIRE_PX2, TimeUnit.SECONDS);
            //判断是否加锁成功
            if (res){
                SkuInfo skuInfo = getSkuInfo(skuId);
                //判断数据库是否为空
                if (skuInfo == null || skuInfo.getId() == null){
                    skuInfo = new SkuInfo();
                    //缓存空值，防止穿透，3秒过期
                    stringRedisTemplate.boundValueOps(key).set(JSONObject.toJSONString(skuInfo),
                            3,TimeUnit.SECONDS);
                    return skuInfo;
                }
                //若不为空
                stringRedisTemplate.boundValueOps(key).set(JSONObject.toJSONString(skuInfo),
                        RedisConst.SKUKEY_TIMEOUT ,TimeUnit.SECONDS);
                //释放锁
                DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
                //设置释放脚本
                redisScript.setScriptText("if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end ");
                //设置返回类型
                redisScript.setResultType(Long.class);
                stringRedisTemplate.execute(redisScript, Arrays.asList(lockKey),uuid);
                return skuInfo;
            }else {
                try {
                    //获取锁失败:线程睡觉1秒,再次尝试
                    Thread.sleep(1000);
                    return getSkuInfo(skuId);
                }catch (Exception e){
                    e.printStackTrace();
                    return null;
                }
            }
        }else {
            //有数据直接返回
            return JSONObject.parseObject(s,SkuInfo.class);
        }

    }

    /**
     * 查询sku的详细信息:使用redisson查询
     *
     * @param skuId
     * @return
     */
    @Override
    public SkuInfo getSkuByRedisson(Long skuId) {
        //sku:123:info
        String key = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKUKEY_SUFFIX;
        System.out.println(key);
        //从缓存中获取sku的信息
        String s = stringRedisTemplate.boundValueOps(key).get();
        //缓存中没有数据
        if (StringUtils.isEmpty(s)){
            //定义锁 sku:123:lock
            String lockKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKULOCK_SUFFIX;
            //获取锁
            RLock lock = redissonClient.getLock(lockKey);
            try {
                //尝试加锁
                boolean flag = lock.tryLock(RedisConst.SKULOCK_EXPIRE_PX1,
                        RedisConst.SKULOCK_EXPIRE_PX2, TimeUnit.SECONDS);
                //判断是否加锁成功
                if(flag){
                    SkuInfo skuInfo = getSkuInfo(skuId);
                    //判断数据库是否为空
                    if (skuInfo == null || skuInfo.getId() == null){
                        skuInfo = new SkuInfo();
                        //缓存空值,防止穿透,3秒过期
                        stringRedisTemplate.boundValueOps(key).set(JSONObject.toJSONString(skuInfo), 3, TimeUnit.SECONDS);
                        return skuInfo;
                    }
                    //若不为空
                    stringRedisTemplate.boundValueOps(key).set(JSONObject.toJSONString(skuInfo),
                            RedisConst.SKUKEY_TIMEOUT, TimeUnit.SECONDS);
                    //返回结果
                    return  skuInfo;
                }else {
                    try {
                        //获取锁失败:线程睡觉1秒,再次尝试
                        Thread.sleep(1000);
                        return getSkuInfo(skuId);
                    }catch (Exception e){
                        e.printStackTrace();
                        return null;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
                return null;
            }

        }else {
            //有数据直接返回
            return JSONObject.parseObject(s, SkuInfo.class);
        }
    }

    /**
     * 根据第三级分类的id查询所有类别的信息(包含一级 二级 三级分类的完整的id和name属性)
     *
     * @param category3Id
     * @return
     */
    @Override
    public BaseCategoryView getCategoryViewByCategory3Id(Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryViewMapper.selectById(category3Id);
        return baseCategoryView;
    }

    /**
     * 获取sku价格
     *
     * @param skuId
     * @return
     */
    @Override
    public BigDecimal getSkuPrice(Long skuId) {
        //查询sku的详细信息
        SkuInfo skuInfo = skuInfoMapper.selectById(skuId);
        //若sku不存在直接返回0
        if (skuInfo == null || skuInfo.getId() == null){
            return BigDecimal.valueOf(0);
        }
        //若sku存在则返回价格
        return skuInfo.getPrice();
    }

    /**
     * 查询指定商品的销售属性
     *
     * @param skuId
     * @param spuId
     * @return
     */
    @Override
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(Long skuId, Long spuId) {
        List<SpuSaleAttr> spuSaleAttrs = spuSaleAttrMapper.selectSpuSaleAttrListCheckBySku(spuId, skuId);
        return spuSaleAttrs;
    }

    /**
     * 查询指定spu的所有销售属性值与sku对应关系
     *
     * @param spuId
     * @return
     */
    @Override
    public Map  getSkuValueIdsMap(Long spuId) {

        //初始化
        Map<Object, Object> result = new HashMap<>();
        //查询所有的键值对
        List<Map> maps = skuSaleAttrValueMapper.selectSkuMap(spuId);
        //遍历处理
        for (Map map : maps) {
            result.put(map.get("sku_id"),map.get("value_id"));
        }
        return result;
    }

    /**
     * 获取全部分类信息
     *
     * @return
     */
    @Override
    public List<JSONObject> getBaseCategoryList() {
        List<JSONObject> result = new ArrayList<>();
        //查询视图获取所有的分类信息
        List<BaseCategoryView> baseCategoryViews = baseCategoryViewMapper.selectList(null);
        //根据一级分类进行归类:此时所有的key都为1级分类的id, value为二级与三级分类的数据
        Map<Long,List<BaseCategoryView>> category1Map =
                baseCategoryViews.stream().collect(Collectors.groupingBy(BaseCategoryView::getCategory1Id));
        //遍历解析各个一级分类的二级分类信息
        for (Map.Entry<Long, List<BaseCategoryView>> category1 : category1Map.entrySet()) {
            JSONObject category1Child = new JSONObject();
            //获取一级分类id
            Long category1Id = category1.getKey();
            //获取一级分类的名字
            String category1Name = category1.getValue().get(0).getCategory1Name();
            //获取所有二级分类
            List<BaseCategoryView> category2List = category1.getValue();
            //根据二级分类再进行聚合
            Map<Long,List<BaseCategoryView>> category2Map =
                    category2List.stream().collect(Collectors.groupingBy(BaseCategoryView::getCategory2Id));
            //存放当前一级分类的所有二级分类
            List<JSONObject> category2ChildList = new ArrayList<>();
            for (Map.Entry<Long, List<BaseCategoryView>> category2 : category2Map.entrySet()) {
                JSONObject category2Child = new JSONObject();
                //获取二级分类id
                Long category2Id = category2.getKey();
                //获取一级分类的名字
                String category2Name = category2.getValue().get(0).getCategory2Name();
                //获取所有二级分类
                List<BaseCategoryView> category3List = category2.getValue();
                //三级分类只保留id和name
                List<JSONObject> category3ChildList = category3List.stream().map(category3 ->{
                    JSONObject category3Child = new JSONObject();
                    //保存id
                    category3Child.put("categoryId",category3.getCategory3Id());
                    //保存名字
                    category3Child.put("categoryName",category3.getCategory3Name());
                    return category3Child;
                }).collect(Collectors.toList());
                //保存二级与三级分类的关系
                category2Child.put("categoryId",category2Id);
                category2Child.put("categoryName",category2Name);
                category2Child.put("categoryChild",category3ChildList);
                //保存二级分类
                category2ChildList.add(category2Child);
            }
            //保存二级与一级分类的关系
            category1Child.put("categoryId",category1Id);
            category1Child.put("categoryName",category1Name);
            category1Child.put("categoryChild",category2ChildList);
            //保存结果
            result.add(category1Child);
        }
        return result;
    }

    /**
     * 查询品牌信息详情
     *
     * @param id
     * @return
     */
    @Override
    public BaseTrademark getById(Long id) {
         return baseTrademarkMapper.selectById(id);

    }

    /**
     * 根据sku的id查询平台属性信息
     *
     * @param skuId
     */
    @Override
    public List<BaseAttrInfo> selectBaseAttrInfoBySku(Long skuId) {
        return baseAttrInfoMapper.selectBaseAttrInfoBySku(skuId);
    }

    /**
     * 删除库存信息
     *
     * @param id
     * @param num
     * @return
     */
    @Override
    public int updateSkuStock(Long id, Integer num) {
        int skuStock = skuInfoMapper.updateSkuStock(id, num);
        if (skuStock == 0){
            return -1;
        }
        return skuStock;
    }

    /**
     * 取消订单库存回滚
     *
     * @param id
     * @param num
     */
    @Override
    public int updateCancelSkuStock(Long id, Integer num) {
        return skuInfoMapper.updateCancelSkuStock(id, num);
    }


    /**
     * 新增品牌
     *
     * @param baseTrademark
     */
    @Override
    public void addTrademark(BaseTrademark baseTrademark) {
        baseTrademarkMapper.insert(baseTrademark);
    }

    /**
     * 修改品牌
     *
     * @param baseTrademark
     */
    @Override
    public void updateTrademark(BaseTrademark baseTrademark) {
        baseTrademarkMapper.updateById(baseTrademark);
    }

    /**
     * 根据Id查询品牌
     *
     * @param id
     * @return
     */
    @Override
    public BaseTrademark getTrademarkById(Long id) {
        BaseTrademark baseTrademark = baseTrademarkMapper.selectById(id);
        return baseTrademark;
    }

    /**
     * 删除品牌
     *
     * @param id
     */
    @Override
    public void deleteTrademarkById(Long id) {
        baseTrademarkMapper.deleteById(id);
    }



}
